package com.jmemoir.base.aop.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

/**
 * 日志切面
 *
 * @author Tellsea
 * @date 2023/8/3
 */
@Slf4j
@Aspect
@Component
public class LoggingAspect {

    /**
     * 环绕切面
     *
     * @param joinPoint
     */
    @Around("execution(* com.jmemoir.base.aop.controller.*.*(..))")
    public Object beforeAdvice(ProceedingJoinPoint joinPoint) throws Throwable {
        log.info("进入切面");
        long startTime = System.currentTimeMillis();
        Object result = joinPoint.proceed();
        long endTime = System.currentTimeMillis();
        long executionTime = endTime - startTime;
        log.info("方法名: " + joinPoint.getSignature().getName() + " 执行时间: " + executionTime + "ms");
        log.info("离开切面");
        return result;
    }
}